package com.kehao.newcoder;

import org.junit.Test;

import java.util.*;

public class NC112Solution {
    public String solve (int M, int N) {
        Map<Integer,Character> map = new HashMap<>();
        StringBuffer sb = new StringBuffer();
        if(M<0){
            M = -M;
            sb.append('-');
        }
        for (int i = 0; i < 10; i++) {
            map.put(i, (char) (i+'0'));
        }
        for (int i = 10; i < 16; i++) {
            map.put(i, (char) (i+'A'-10));
        }
        List<Character> list = new ArrayList<>();
        while (M!=0){
            int left = M % N;
            list.add(map.get(left));
            M = M/N;
        }
        Collections.reverse(list);
        for (Character character : list) {
            sb.append(character);
        }
        return sb.toString();
    }

    @Test
    public void test(){
        String solve = solve(23, 12);
        System.out.println(solve);
    }
}
